package com.forest.gissingle.dialog;

import java.util.ArrayList;
import java.util.List;

import com.forest.gissingle.R;
import com.forest.gissingle.adapter.ListOverlayAdapter;
import com.forest.gissingle.interfaces.IDialog;
import com.google.android.gms.maps.GoogleMap;

import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class RoadsDialog extends MDialog implements IDialog,
		android.view.View.OnClickListener, OnItemClickListener {
	/**
	 * 
	 * @param context
	 * @param sdbListerner
	 * @param flag
	 *            delete=0;back isNewItemtrue=1;back isNewItemfalse=2
	 */
	private TextView title;
	private TextView message;
	private LinearLayout content;
	private Button confirm;
	private Button cancel;

	private Context context;
	private Resources res;
	private int flag;

	LayoutInflater inflater;
	private GoogleMap map;

	public RoadsDialog(Context context, Resources res, GoogleMap map) {
		super(context, R.style.dialog, R.layout.dialog_overlay_choose);
		this.context = context;
		this.res = res;
		iDialog = this;
		inflater = LayoutInflater.from(context);
		this.map = map;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setHeightOfScreen(0.9f);
	}

	@Override
	public void initView() {
		title = (TextView) findViewById(R.id.dialog_title);
		message = (TextView) findViewById(R.id.dialog_message);
		content = (LinearLayout) findViewById(R.id.dialog_content);
		confirm = (Button) findViewById(R.id.dialog_confirm);
		cancel = (Button) findViewById(R.id.dialog_cancel);

		content.removeAllViews();
		inflater.inflate(R.layout.view_listview, content);
		ListView mListView = (ListView) content.getChildAt(0);
		ArrayList<String> overlayout = new ArrayList<String>();
		overlayout.add("11");
		overlayout.add("12");
		overlayout.add("13");
		ListOverlayAdapter mAdapter = new ListOverlayAdapter(context,
				overlayout);
		mListView.setAdapter(mAdapter);
		mListView.setOnItemClickListener(this);
		// // 依据状态显示文本
		// switch (flag) {
		// case 0:
		// title.setText(res.getString(
		// R.string.saving_mode_edit_dialog_title_delete,
		// bean.getName()));
		// message.setText(res
		// .getString(R.string.saving_mode_edit_dialog_message_delete));
		// break;
		// case 1:
		// title.setText(res.getString(
		// R.string.saving_mode_edit_dialog_title_discharge,
		// bean.getName()));
		// message.setText(res.getString(
		// R.string.saving_mode_edit_dialog_message_discharge,
		// bean.getName()));
		// break;
		// case 2:
		// title.setText(res
		// .getString(R.string.saving_mode_edit_dialog_title_nochange));
		// message.setText(res
		// .getString(R.string.saving_mode_edit_dialog_message_nochange));
		// break;
		// default:
		// break;
		// }
		// confirm.setText(res.getString(R.string.saving_mode_edit_text_confirm));
		// cancel.setText(res.getString(R.string.saving_mode_edit_text_cancel));
	}

	@Override
	public void setListener() {
		confirm.setOnClickListener(this);
		cancel.setOnClickListener(this);
	}

	@Override
	public void resume() {

	}

	@Override
	public void resize() {

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.dialog_confirm:
			this.dismiss();
			break;
		case R.id.dialog_cancel:
			this.dismiss();
			break;
		default:
			break;
		}
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		// map.addGroundOverlay(GMapGroundManager.getInstance()
		// .getGroundOptSample());
		this.dismiss();
	}

}
